<?php
namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Messages\Message;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use App\Models\Goods;
use App\Models\GoodsClass;
use Log;

class GoodsController extends Controller
{

    /**
     * @api {post} /goods/list
     * 商品列表
     */
    public function list(Request $request)
    {
        $rules = [
            'page'            => 'integer|min:1',
            'per_page'        => 'required_with:page|integer|min:1',
            'brand'           => 'integer|min:0',
            'category'        => 'integer|min:0',
            // 'keyword'         => 'string',
        ];

        if ($error = $this->validateInput($rules)) {
            return $error;
        }

        $data = Goods::getList($this->validated);

        return $this->output(200, $data);
    }

     /**
     * @api {post} /goods/info
     * 商品详情
     */

    public function info()
    {
        $rules = [
            'goods_id' => 'required|integer|min:1',
        ];

        if ($error = $this->validateInput($rules)) {
            return $error;
        }

        $data = Goods::getInfo($this->validated);

        return $this->output(200, $data);
    }

    /**
     * @api {post} /goods/category
     * 分类列表
     */
    public function category(Request $request)
    {
        // $rules = [
        //     'page'            => 'integer|min:1',
        //     'per_page'        => 'required_with:page|integer|min:1',
        //     // 'brand'           => 'integer|min:0',
        //     // 'category'        => 'integer|min:0',
        //     // 'keyword'         => 'string',
        // ];

        // if ($error = $this->validateInput($rules)) {
        //     return $error;
        // }

        $data = GoodsClass::getCategroyList();

        return $this->output(200, $data);
    }



}
